package com.zzg.springboot.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name = "book")
public class Book {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private int id;

    @Column(name = "name")
    private String name;

    @OneToOne(cascade = CascadeType.ALL)  // 指定关系(一对一)
    @JoinColumn(name = "book_detail_id")  // 指定关联的字段(外键字段)
    private BookDetail bookDetail;
    
    @OneToOne  // 指定关系(一对一)
    @PrimaryKeyJoinColumn // 指定关联的字段(默认主键字段)
    private BookDesc bookDesc;
    
    @OneToOne // 指定关系(一对一)
    @JoinTable(name = "book_detail_middle", joinColumns = @JoinColumn(name = "book_id"), inverseJoinColumns = @JoinColumn(name = "detail_id", unique = true)) //通过关联表(两个关联字段)
    private BookDetail detail;


	public Book() {
    }

    public Book(String name, BookDetail bookDetail) {
        this.name = name;
        this.bookDetail = bookDetail;
    }
    
    public BookDetail getDetail() {
		return detail;
	}

	public void setDetail(BookDetail detail) {
		this.detail = detail;
	}

	public BookDesc getBookDesc() {
		return bookDesc;
	}

	public void setBookDesc(BookDesc bookDesc) {
		this.bookDesc = bookDesc;
	}


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public BookDetail getBookDetail() {
		return bookDetail;
	}

	public void setBookDetail(BookDetail bookDetail) {
		this.bookDetail = bookDetail;
	}
	
    
    
}
